// JavaScript Document
/*******************************************************************************
 * 评论
 ******************************************************************************/ 
	
function replyTo(commentID, toPerson){
	$('#comment'+commentID).focus().val('回复'+toPerson+'：');// 使得光标在最后：将文本框中值，复制|清空|粘贴
	
}
function replyCommit(commentID,count){
	var comment=$('#comment'+commentID).val();
	var url= '/home/replycomment';
	var msg_suc="评论成功";
	var msg_fail="评论失败";
	var span_id='span_'+commentID;
	$.ajax({
		type : 'post',
		url : url,
		data : {inajax:'2', commentmsg:comment, comID:commentID},
		dataType : 'json',
		success : function(data){				
			data = $.trim(data);
			switch(data[0]){
				case "1":message(msg_suc, 'notice');unfoldComment_1(commentID);	count++;var countstr='('+count+')';$('#'+span_id).text(countstr);break;
				case "2":message(msg_fail, 'notice');break;
			}			 
			wind_hide();			
		}
	});
	
}

function unfoldComment_1(ctsid){
	var url= '/home/unfoldcomment';
	 
	  $.ajax({
		  type : 'post',
		  url : url,
		  data : {inajax:'1', ctsID:ctsid},
		  dataType : 'html',
		  success : function(data){
			  data = $.trim(data);
			  $('#cts'+ctsid).html(data);
		  }
	  }); 
	  $('#a'+ctsid).removeClass('folded');
  	  $('#a'+ctsid).addClass('unfolded');
	 

}

function unfoldComment(ctsid){
	var url= '/home/unfoldcomment';
	var c = document.getElementById("a"+ctsid).className;
	if(c=='folded'){
	  $.ajax({
		  type : 'post',
		  url : url,
		  data : {inajax:'1', ctsID:ctsid},
		  dataType : 'html',
		  success : function(data){
			  data = $.trim(data);
			  $('#cts'+ctsid).html(data);
		  }
	  }); 
	  $('#a'+ctsid).removeClass('folded');
  	  $('#a'+ctsid).addClass('unfolded');
	}else{
		$('#a'+ctsid).removeClass('unfolded');
	  	$('#a'+ctsid).addClass('folded');
		$('#cts'+ctsid).html('');
	}

}

function moreComment(){
	var count_this = $('#count_this').val();
	var count_count = $('#count_count').val();
	var options = 
	{
			type : 'post',
			url : '/home/morecomment',
			data : {inajax:2, count_this:count_this, count_count:count_count},
			dataType : 'json',
			success : function(data){												
				//data = $.trim(data);
				if(data.code == 0){
					$('#getmore').attr('value', '没有更多数据了');
				}
				if(data.code == 1){
					$('#getmore').attr('value', '没有获得数据');
				}
				if(data.code == 2){
					$('#more-li').before(data.html);
					count_count = parseInt(count_count) - 1;
					$('#count_count').attr('value', count_count);
					count_this = parseInt(count_this) + 1;
					$('#count_this').attr('value', count_this);
				}							
			}
	}
	//如果秒数大于0，才开始
	if(count_count > 0){
		$.ajax(options);
	}
	
	
	
	
}
/*******************************************************************************
 * 编辑器
 ******************************************************************************/ 
// 变量
var editor;
var ColorArray=new Array('000000','993300','333300','003300','800000','FF6600','808000','008000','FF0000','FF9900',
	'99CC00','339966','FF00FF','FFCC00','FFFF00','00FF00');  
var current=null;  

	function select_change(ep,pid){
		var value=$('select[name='+ep+']').val();
		if(value=='2'){
			$('select[name='+pid+']').attr('disabled',false);
		}else{
			$('select[name='+pid+']').attr('disabled',true);
		}
	}


// 率先载入 |iframe编辑
function editframe(iframeid,contentid){  
	// var o=document.getElementById("noteadd");
	editor=document.getElementById(iframeid).contentWindow; 
	editor.document.designMode = 'On';
	editor.document.contentEditable = true; 
	editor.document.body.style.fontSize='14px';  
	editor.document.body.style.fontFamily='微软雅黑';
	var colorpanelid=iframeid+"cp"; 
	document.body.onload = intocolor();
	
}
	function setContentVal(iframeid,contentid){
		var iframecontent=document.getElementById(iframeid).contentWindow.document.getElementsByTagName("body")[0].innerHTML;			
		$('input[name='+contentid+']').attr("value",iframecontent);
	}
	
　　function t(s)
　　{
　　　editor.document.execCommand(s,false,null);
　　} 
	function tcolor(s,color)
　　{
　　　editor.document.execCommand(s,false,color);
　　} 
 
	function intocolor(){  
	var colorTable='';  
	for (i=0;i<4;i++){
	  colorTable=colorTable+'<tr height=12>'; 
	  for (j=0;j<4;j++){  
	 
		colorTable=colorTable+'<td class="colortd" width=11 style="background-color:#'+ColorArray[i*4+j]+'"/>';
	  
	  }  
	  colorTable=colorTable+'</tr>'; 
	}  
	colorTable='<table class="colortable" onclick="doclick()" onmouseover="doOver()">'+colorTable+'</table>';   
	colorpanel.innerHTML=colorTable;
	}  

  
	function doOver() {  
	  if ((event.srcElement.tagName=="TD") && (current!=event.srcElement)) {  
		if (current!=null){
			current.style.backgroundColor = current._background;
		}   
		event.srcElement._background = event.srcElement.style.backgroundColor;
		DisColor.style.backgroundColor = event.srcElement.style.backgroundColor;  
		HexColor.value = event.srcElement.style.backgroundColor.toUpperCase();  
		event.srcElement.style.backgroundColor = "white" ; 
		current = event.srcElement; 
	  }  
	}  
	
	function doclick(){  
	  if (event.srcElement.tagName == "TD")  
	  {  
		var clr = event.srcElement._background;  
		tcolor("ForeColor",clr);
		DisplayClrDlg(false);  
		return clr;  
	  }  
	}  
// 选择颜色--------触发事件
	function ShowPanel(){ 
		DisplayClrDlg(true); 
		addEvent(document.body,"mousedown",clickOther);
	}

	function addEvent(obj,eventType,func){
		if(obj.attachEvent){
			obj.attachEvent("on" + eventType,func);
		}else{
			obj.addEventListener(eventType,func,false);
		}
	}
	  
	function clickOther(el){
		thisObj = el.target?el.target:event.srcElement; 
		if(!(thisObj.className=="colortd")){ 
			DisplayClrDlg(false);  
		}
		 
	}
 
	// 显示颜色对话框
	// display 决定显示还是隐藏
	// 显示位置
	function DisplayClrDlg(display){  
	  var clrPanel = document.getElementById('colorpanel');  
	  if (display){  	   
		var left = document.getElementById("colorwheel").offsetLeft;  
		var top = document.getElementById("colorwheel").offsetHeight+document.getElementById("colorwheel").offsetTop;
		clrPanel.style.pixelLeft = left;  
		clrPanel.style.pixelTop = top;  
		clrPanel.style.display = "block";   
	  }  
	  else{  
		clrPanel.style.display = "none";  
	  }  
	}
	

	
	function note_commit(iframeid,subjectname){
// var subject=$('input[name=subjectname]').val();
		var subject=document.getElementsByName(subjectname)[0].value;// 用jquery怎样
		var content=document.getElementById(iframeid).contentWindow.document.getElementsByTagName("body")[0].innerHTML;
		var url= '/notepad/addnote';
		var id=$('#noteid').val();
		var msg_suc="添加成功";
		var msg_fail="添加失败";
		if(id>0){	
			url = '/notepad/editnote'; 
			msg_suc="修改成功";
			msg_fail="修改失败";
		}else{
			id=-1;
		}		 
		$.ajax({
		type : 'post',
		url : url,
		data : {inajax:'1', notesubject:subject, notecontent:content, noteid:id},
		dataType : 'json',
		success : function(data){
			data = $.trim(data);
			switch(data[0]){
				case "1":message(msg_suc, 'notice');break;
				case "2":message(msg_fail, 'notice');break;			
			}			 
			if(wind_is_open){
				loading_hide();
				wind_hide();
			}else{
				window.location.href="/notepad/notelist";
			}
		}
		});
	}
	 